package demoMod.stsconsole.commands;

import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.enums.ErrType;
import demoMod.stsconsole.helpers.LocalizedStrings;
import demoMod.stsconsole.rooms.AbstractRoom;

import java.util.List;
import java.util.Scanner;
import java.util.function.Function;

public class Goto extends AbstractCommand {
    public static Function<Void, Boolean> condition = v -> AbstractDungeon.currDungeon.currMapNode.room.phase != AbstractRoom.RoomPhase.COMPLETED;

    @Override
    public void execute(String[] args, Scanner sc) {
        if (args.length != 1) {
            this.errMsg(ErrType.WRONG_ARGUMENT);
            return;
        }
        try {
            int index = Integer.parseInt(args[0]);
            List<String> cmdStrings = LocalizedStrings.getCommandStrings("Goto");
            if (condition.apply(null)) {
                System.out.println(cmdStrings.get(0));
                return;
            }
            if (!AbstractDungeon.currDungeon.map.gotoNode(index)) {
                this.errMsg(ErrType.WRONG_ARGUMENT);
            } else {
                System.out.println(cmdStrings.get(1));
            }
        } catch (NumberFormatException e) {
            this.errMsg(ErrType.WRONG_ARGUMENT);
        }
    }

    @Override
    public boolean requiredPrompt(String currentPrompt) {
        return currentPrompt.contains("Dungeon/");
    }
}
